import javax.sound.sampled.EnumControl;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

class Solution1218 {
    public static void main(String[] args) {
       int[] arr = {1 , 2 , 3  ,4} ;
        System.out.println(longestSubsequence(arr, 1));
    }
    public static int longestSubsequence(int[] arr, int difference) {
       Map<Integer , Integer> map  = new HashMap<>() ;
       int n = arr.length ;
       int[] dp = new int[n] ;
       int max = 1 ;
       for(int i=0 ; i < n ; i ++){
           dp[i] = 1 ;
           if(map.containsKey(arr[i] - difference)){
               dp[i] += dp[map.get(arr[i]-difference)] ;
           }
           max = Math.max(max , dp[i]) ;
           map.put(arr[i] , i );
       }

        return max  ;
    }
}